<?php
			
$ini = ini_set("soap.wsdl_cache_enabled", 0);
if(!isset($_COOKIE['MySession'])){
	$url = "https://eden.iwsdev.com/freeway/custom/webservices/index.php?service=Session";
	$Client = new SoapClient($url);
	if(isset($_SESSION[cart][customer_id])){
		$Client->__setCookie('customer_id', $_SESSION[cart][customer_id]);
	}
	$this_Session = $Client->returnSID();
	setcookie('MySession', $this_Session);
	unset($Client);	
}
else 
	$this_Session = $_COOKIE['MySession'];

$url = "https://eden.iwsdev.com/freeway/custom/webservices/index.php?service=getEvents";
$Client = new SoapClient($url);
$Client->__setCookie('ws_freeway', $this_Session);
if(isset($_SESSION[cart][customer_id])){
	$Client->__setCookie('customer_id', $_SESSION[cart][customer_id]);
}

$allEvents = $Client->listEvents();
unset($Client);
/*
echo '<pre>';
var_dump($allEvents["fullDetails"]);
echo '<pre>';
*/
$count = 0;
//print_r($_SESSION);
$startTable =	'<table class="data" border="0" cellspacing="0" cellpadding="0">' .PHP_EOL;
$startTable .= '<tr>' .PHP_EOL;
$startTable .= '<th colspan="3" nowrap="nowrap">Schedule</th>' .PHP_EOL;
$startTable .= '<th nowrap="nowrap">&nbsp;</th>' .PHP_EOL;
$startTable .= '<th colspan="2" nowrap="nowrap">Location</th>' .PHP_EOL;
$startTable .= '<th nowrap="nowrap"></th>' .PHP_EOL;
$startTable .= '<th nowrap="nowrap"></th>' .PHP_EOL;
$startTable .= '<th nowrap="nowrap"></th>' .PHP_EOL;
$startTable .= '<th nowrap="nowrap">Register</th>' .PHP_EOL;
$startTable .= '</tr>';

foreach ($allEvents["fullDetails"] as $event){
		if($count == 0 || $CourseCode != $event[events_categories_name]){
				$CourseCode =	$event[events_categories_name];
				$endTable = ($count>0) ? '</table><br /><br />': '';
				$pre = $endTable.PHP_EOL.'<h4>Course Code: '.$CourseCode.'</h4>'.$startTable;
			}
			$row_type = ($count++ % 2 == 0) ? 'roweven': 'rowodd';
			$dates = explode(',',strip_tags($event[events_description]));
			$start = $dates[0];
			$end = $dates[1];
			$location = explode(',', $event[location_name]);
			$location1 = $location[0];
			$location2 = $location[1];
			$url = 'http://eden.iwsdev.com/training';
			$title = $event[events_name];
			$register_url = 'https://eden.iwsdev.com/index.php?page=register-course&item='.$event[events_id].'&session='.$event[sessions_id];
			
			$display = "<tr class=".$row_type.">" .PHP_EOL;
			$display .= "<td align=\"center\">".$start."</td>" .PHP_EOL;
			$display .= "<td> - </td>" .PHP_EOL;
			$display .= "<td align=\"center\">$end</td>" .PHP_EOL;
			$display .= "<td> </td>" .PHP_EOL;
			$display .= "<td>$location1,</td>" .PHP_EOL;
			$display .= "<td><a href=".$url.">$location2</a></td>" .PHP_EOL;
			$display .= "<td></td>" .PHP_EOL;
			$display .= "<td><a href=".$url.">$title</a></td>" .PHP_EOL;
			$display .= "<td></td>" .PHP_EOL;
			$display .= "<td><a href=".$register_url.">Register</a></td>" .PHP_EOL;
			$display .= "</tr>" .PHP_EOL;

			echo $pre.$display;
			$pre = '';
}
echo '</table>';
			
?>